package com.tianye.lc.activity;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewStub;
import android.widget.LinearLayout;

import com.tianye.lc.R;
import com.tianye.lc.outer.SystemBarTintManager;

/**
 * Created by yangyazhou on 2016/12/20.
 */

public class BaseActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void setContentView(int layoutResID) {
        LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.activity_base, null);
        View sonLayout = getLayoutInflater().inflate(layoutResID, null);
        layout.addView(sonLayout);
        super.setContentView(layout);

        initTitle();

        //设置沉浸式状态拦
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            SystemBarTintManager.setTranslucentStatus(this, true);
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(R.color.white);
        }
    }

    private void initTitle() {
        ViewStub baseTitle = (ViewStub) findViewById(R.id.base_title);
        baseTitle.setLayoutResource(getTitleLayout());
        baseTitle.inflate();


        View back = findViewById(R.id.back);
        if (null != back) {
            back.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
        }
    }

    protected int getTitleLayout() {
        return R.layout.title_view_2;
    }

}
